#!/bin/bash

hive_db_name=gmall
mysql_db_name=gmall

export_data() {
/opt/bdp/sqoop/bin/sqoop export \
-Dmapreduce.job.queuename=hive \
--connect "jdbc:mysql://hadoop101:3306/${mysql_db_name}?useUnicode=true&characterEncoding=utf-8"  \
--username root \
--password 123456 \
--table $1 \
--num-mappers 1 \
--export-dir /warehouse/$hive_db_name/ads/$1 \
--input-fields-terminated-by "\t" \
--update-mode allowinsert \
--update-key $2 \
--input-null-string '\\N'    \
--input-null-non-string '\\N'
}

case $1 in
  "ads_uv_count")
     export_data "ads_uv_count" "dt"
;;
  "ads_user_action_convert_day")
     export_data "ads_user_action_convert_day" "dt"
;;

#!/bin/bash

start-web(){
        for i in hadoop101;
        do
                ssh $i "cd /opt/bdp/azkaban/azkaban-web;bin/start-web.sh"
        done
}

stop-web(){
        for i in hadoop101;
        do
                ssh $i "cd /opt/bdp/azkaban/azkaban-web;bin/shutdown-web.sh"
        done
}

start-exec(){
        for i in hadoop101 hadoop102 hadoop103;
        do
                ssh $i "cd /opt/bdp/azkaban/azkaban-exec;bin/start-exec.sh"
        done
}

activate-exec(){
        for i in hadoop101 hadoop102 hadoop103;
        do
                ssh $i "curl -G "$i:12321/executor?action=activate" && echo"
        done
}

stop-exec(){
        for i in hadoop101 hadoop102 hadoop103;
        do
                ssh $i "/opt/bdp/azkaban/azkaban-exec/bin/shutdown-exec.sh"
        done
}

case $1 in
        start-exec)
                start-exec;;
        activate-exec)
                activate-exec;;
        stop-exec)
                stop-exec;;
        start-web)
                start-web;;
        stop-web)
                stop-web;;
esac
